using System;
using System.Data;

using SqlHelperForCry.Common;

namespace Torch.WL.Entity
{
    [Table("Tb_Sys_Modules", "ModuleID", "Torch.WL.ConnectionString")]
	public class Tb_Sys_Modules : Info
	{
		#region SQL column name consts 
		public const string SQLCOL_MODULEID = "ModuleID";
		public const string SQLCOL_MODULETYPEID = "ModuleTypeID";
		public const string SQLCOL_MODULENAME = "ModuleName";
		public const string SQLCOL_MODULETAG = "ModuleTag";
		public const string SQLCOL_MODULEURL = "ModuleURL";
		public const string SQLCOL_MODULEDISABLED = "ModuleDisabled";
		public const string SQLCOL_MODULEORDER = "ModuleOrder";
		public const string SQLCOL_MODULEDESCRIPTION = "ModuleDescription";
		public const string SQLCOL_ISMENU = "IsMenu";
		public const string SQLCOL_TARGET = "Target";
		#endregion


		#region Contructors
		/// <summary>
		/// Construct empty entity
		/// </summary>
		public Tb_Sys_Modules () {}

		/// <summary>
		/// Construct entity by primary key, other fields will be assigned by 
		/// "Load" method.
		/// </summary>
		public Tb_Sys_Modules (int ModuleID)
		{
			this.ModuleID = ModuleID;
		}
		#endregion

		public override void Init (DataRow row)
		{
			ModuleID = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_MODULEID]);
			ModuleTypeID = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_MODULETYPEID]);
			ModuleName = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_MODULENAME]);
			ModuleTag = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_MODULETAG]);
			ModuleURL = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_MODULEURL]);
			ModuleDisabled = (bool)ObjectType.BooleanTypeHelper.Read(row[SQLCOL_MODULEDISABLED]);
			ModuleOrder = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_MODULEORDER]);
			ModuleDescription = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_MODULEDESCRIPTION]);
			IsMenu = (bool)ObjectType.BooleanTypeHelper.Read(row[SQLCOL_ISMENU]);
			Target = (bool)ObjectType.BooleanTypeHelper.Read(row[SQLCOL_TARGET]);
		}

		#region Properties 
		#region Property <int> ModuleID
		[Property("ModuleID", 4, SqlDbType.Int, true, true)]
		public int ModuleID 
		{
			get { return _ModuleID; }
			set { _ModuleID = value; }
		}
		private int _ModuleID = int.MinValue;
		#endregion

		#region Property <int> ModuleTypeID
		[Property("ModuleTypeID", 4, SqlDbType.Int, false, false)]
		public int ModuleTypeID 
		{
			get { return _ModuleTypeID; }
			set { _ModuleTypeID = value; }
		}
		private int _ModuleTypeID = int.MinValue;
		#endregion

		#region Property <string> ModuleName
		[Property("ModuleName", 60, SqlDbType.NVarChar, false, false)]
		public string ModuleName 
		{
			get { return _ModuleName; }
			set { _ModuleName = value; }
		}
		private string _ModuleName = null;
		#endregion

		#region Property <string> ModuleTag
		[Property("ModuleTag", 100, SqlDbType.NVarChar, false, false)]
		public string ModuleTag 
		{
			get { return _ModuleTag; }
			set { _ModuleTag = value; }
		}
		private string _ModuleTag = null;
		#endregion

		#region Property <string> ModuleURL
		[Property("ModuleURL", 1000, SqlDbType.NVarChar, false, false)]
		public string ModuleURL 
		{
			get { return _ModuleURL; }
			set { _ModuleURL = value; }
		}
		private string _ModuleURL = null;
		#endregion

		#region Property <bool> ModuleDisabled
		[Property("ModuleDisabled", 1, SqlDbType.Bit, false, false)]
		public bool ModuleDisabled 
		{
			get { return _ModuleDisabled; }
			set { _ModuleDisabled = value; }
		}
		private bool _ModuleDisabled = false;
		#endregion

		#region Property <int> ModuleOrder
		[Property("ModuleOrder", 4, SqlDbType.Int, false, false)]
		public int ModuleOrder 
		{
			get { return _ModuleOrder; }
			set { _ModuleOrder = value; }
		}
		private int _ModuleOrder = int.MinValue;
		#endregion

		#region Property <string> ModuleDescription
		[Property("ModuleDescription", 100, SqlDbType.NVarChar, false, false)]
		public string ModuleDescription 
		{
			get { return _ModuleDescription; }
			set { _ModuleDescription = value; }
		}
		private string _ModuleDescription = null;
		#endregion

		#region Property <bool> IsMenu
		[Property("IsMenu", 1, SqlDbType.Bit, false, false)]
		public bool IsMenu 
		{
			get { return _IsMenu; }
			set { _IsMenu = value; }
		}
		private bool _IsMenu = false;
		#endregion

		#region Property <bool> Target
		[Property("Target", 1, SqlDbType.Bit, false, false)]
		public bool Target 
		{
			get { return _Target; }
			set { _Target = value; }
		}
		private bool _Target = false;
		#endregion
		#endregion


		public bool LoadByIdentity(int ModuleID)
		{
			return DataAccess.SelectByIdentity(this, Convert.ToInt64(ModuleID));
		}


		public bool DeleteByIdentity()
		{
			return DataAccess.DeleteByIdentity(this);
		}
	}
}
